﻿using System;
using System.Collections.Generic;
using System.Text;
using LdtJudge.DataEngine.CallInterface.ConfiCenter;
using LdtJudge.DataEngine.Common;
using LdtJudge.DataEngine.Model.CommModel;
using Newtonsoft.Json;

namespace LdtDataEngin.ModuleDetail.BaseModule.UserCenter
{
    /// <summary>
    /// 用户中心服务
    /// </summary>
    public class UserCenterProxy
    {
        /// <summary>
        /// 用户中心服务-通过用户名称获取用户信息
        /// </summary>
        /// <param name="url">请求地址</param>
        /// <param name="postData">请求参数</param>
        /// <returns></returns>
        public UserInfoResponse GetUserInfoByName(string url,string postData)
        {
            UserInfoResponse response = new UserInfoResponse();
            response.Result = new Result { Code = "1", Message = "成功" };
            try
            {
                string re = string.Empty;
                
                re = HttpHelp.HttpPostJson(url, postData);
                if (string.IsNullOrWhiteSpace(re))
                {
                    response.Body = null;
                }
                else
                {
                    var userResult = JsonConvert.DeserializeObject<UserInfoResponse>(re);
                    if (userResult != null && userResult.Result.Code == "1" && userResult?.Body!=null)
                    {
                        response.Body = userResult.Body;
                    }
                    else
                    {
                        response.Result.Code = "0";
                        response.Result.Message = userResult.Result.Message;
                    }
                }
            }
            catch (Exception ex)
            {

                response.Result.Code = "0";
                response.Result.Message = ex.ToString();
                response.Body = null;
            }
            return response;
        }

    }
}
